<?php
/**
 * @name 登录
 *
 */
//error_reporting(E_ALL);
class admin_controller_admin_login extends AdminController {
	
	public function __construct($app, $controller){
		parent::__construct($app, $controller);
	}
	/**
	 * @name 登录界面
	 * @ignore
	 */
	public function login_form_action(){
		$this->frameView = $this->viewDir."/login_form.phtml";
	}
	/**
	 * @name 登录
	 * @ignore 
	 */
	public function login_action(){
		$login	=	Model::factory('member_model_data')->login($this->username,$this->password);
		$to = _('to');
		if($login && $login['uid']){
			if(!Model::factory('admin_model_user')->has($login['nickname'])){
				$this->_renderSingle('login_error');
			}else{
				admin_util_login::setSession($login['uid']);
				$this->view = null;
				if($to)
					header('location: '.$to);
				else{
					$this->_redirect('index','index','index',array());
				}
			}
		}else{
			$this->_renderSingle('login_error');
		}
		$this->render(null);
	}
	
	/**
	 * 退出登陆
	 *
	 */
	public function logout_action(){
		if(self::$login['uid']){
			/**
			 * 注销后台登陆
			 */
			admin_util_login::unsetSession(self::$login['uid']);
			/**
			 * 注销前台登录
			 */
			member_util_login::logout();
		}
		$this->_redirect('index','index','index',array());
	}
	
}